// 打开导入窗体函数变量
var openImportActiveForm;

// 未登录提示窗体函数
//var nologonConfirmFrom;

//未登录/登录提示窗体函数
var confirmLoginView;

/**
 * 判断用户是否登陆
 */
function isLogin(){
	
	var is = false;
	
	var sels;
	
	dwr.engine.setAsync(false);
		
	itripservice.isLogin({
		  callback:function(data) {
			sels = data;
		  },
		  errorHandler:function(message){}
	});	
		
	dwr.engine.setAsync(true); 
	
	if(!sels){
		is = false;
	} else {
		is = true;
	}
	
	return is;
}

/**
 * 根据是否登录弹出确认窗体函数(用系统的弹出窗口)(homela)
 * homela
 */
confirmLoginView = function(obj,segmentid){

	//如果退出登录时，再点"加入我的行程"时，弹出"请先登录!"对话框(homela)
	if(!isLogin()){
		if(confirm("亲爱的用户，您尚未登录！是否现在登录?")){
			window.location = $("#pro_path").val() + "/viewLogin.htm";
		} else{
			return;
		}
	} else {
		openImportActiveForm(this,segmentid);
	}
	
}

// 航空信息查询
$(document).ready(function() {
	
	// 窗口最大化
	maxWindow();
	
	// ----打印----
    $("#printbutton").click(function(){
        var printwin = window.open($("#pro_path").val()+"/airlineprint.htm");   		
    });	 
	
	// ----发送邮件----
	var emailmodel=new ModelDiv();

	$("#mailsendbutton").click(function(){
		
		showEmailForm();
		
		var top = $(this).offset().top;
	
		var left = $(this).offset().left;
	
		emailmodel.setOutDiv("emailfadediv");
	
		emailmodel.setInnerDiv("emaillightdiv");
	
		emailmodel.setHit(180);
	
		emailmodel.setWid(350);
	
		emailmodel.setTitle("发送邮件");
	
		emailmodel.setTop(top+13);
	
		emailmodel.setLeft(left-76);
	
		emailmodel.show();

	});  
    
    $("#emailsendclosebutton").click(function(){
    	hiddenEmailForm();  		
    });	    
    
    $("#sendemailtxt").blur(function(){
    	
    	if(document.activeElement.id!="sendemailhidformclosebutton" && 
    			document.activeElement.id!="emailsendclosebutton"){
    		chkEmail();
    	}
    	  		
    });	 
    
    $("#sendemailtxt").focus(function(){
		$("#emailcheckinfotr").css("display","none");
		$("#emailchecksuccessdiv").css("display","none");	
    });	    
    
    // 邮箱输入框响应enter事件
    $("#sendemailtxt").keydown(function(event){
    	if(event.keyCode==13){
    		chkEmail();
    	}
    });  
    
    // 隐藏邮件发送窗口
    $("#emailsendsuccessclosebutton").click(function(){
    	hiddenEmailForm();  	
    });	       
    
    // 隐藏邮件发送窗口
    $("#sendemailhidformclosebutton").click(function(){
    	hiddenEmailForm();  	
    });	       
    
    // 邮件发送按钮点击事件，发送邮件
    $("#emailsendbutton").click(function(){
    	if(chkEmail()==0){
	    	var email = $("#sendemailtxt").val();
	    	var emailContent = $("#printtripdiv").html();
	    	sendtoemail.sendToEmail([email],'行程信息',emailContent,{
				  callback:function(data) {
	    			showsendemailsuccess();
	    		  },
	    		  errorHandler:function(message) {
	    			showsendemailerror();    			  
	    		  }
	    	});
	    	
	    	loadsendemailbar();
	    	
    	} else {
    		return ;
    	}
    });	      
    
	// ----发送短信----
	var messagemodel=new ModelDiv();

	$("#messagesendbutton").click(function(){
		
		showMessageForm();
		
		var top = $(this).offset().top;
	
		var left = $(this).offset().left;
	
		messagemodel.setOutDiv("messagefadediv");
	
		messagemodel.setInnerDiv("messagelightdiv");
	
		messagemodel.setHit(200);
	
		messagemodel.setWid(350);
	
		messagemodel.setTitle("发送短信");
	
		messagemodel.setTop(top+13);
	
		messagemodel.setLeft(left-160);
	
		messagemodel.show();

	});  
    
	// 短息发送关闭按钮
    $("#messagesendclosebutton").click(function(){
    	hiddenMessageForm();  		
    });	    
    
    // 短信发送手机号输入框
    $("#sendmessagetxt").blur(function(){
    	if(document.activeElement.id!="sendmessagehidformclosebutton" && 
    			document.activeElement.id!="messagesendclosebutton"){    	
    		chkMessage();  		
    	}
    });	
    
    $("#sendmessagetxt").focus(function(){
		$("#messagecheckinfotr").css("display","none");
		$("#messagechecksuccessdiv").css("display","none");	
    });	    
    
    // 手机输入框响应enter事件
    $("#sendmessagetxt").keydown(function(event){
    	if(event.keyCode==13){
    		chkMessage();
    	}
    });
    
    // 关闭发送短信窗口
    $("#messagesendsuccessclosebutton").click(function(){
    	hiddenMessageForm();  	
    });	     
    
    $("#sendmessagehidformclosebutton").click(function(){
    	hiddenMessageForm();  	
    });	         
    
    // 发送短息按钮，发送短信
    $("#messagesendbtn").click(function(){
    	if(chkMessage()==0){
	    	var mobile = $("#sendmessagetxt").val();
	    	var messageContent = $("#mobilealertdiv").html();
	    	sendtrip.sendToMobile(messageContent,mobile,{
				  callback:function(data) {
	    			showsendmessagesuccess();
	    		  },
	    		  errorHandler:function(message) {
	    			showsendmessageerror();    			  
	    		  }
	    	});
	    	
	    	loadsendmessagebar();
	    	
    	} else {
    		return ;
    	}
    });	    
    
    // 关闭导入活动窗口
    $("#importactiveclosebutton").click(function(){
    	hiddenImportActiveForm();  	
    });	   

    $("#importactivecancelbutton").click(function(){
    	hiddenImportActiveForm();  	
    });	       
    
    
    // 导入活动开始日期
    $("#activestartdate").bind("focus", function() {

        //WdatePicker({skin:'whyGreen'});             
    	WdatePicker({onpicked:function(){$(this).change();},skin:'whyGreen',isShowClear:false});
    }); 
    
    // 导入活动结束日期
    $("#activeenddate").bind("focus", function() {

        //WdatePicker({skin:'whyGreen'});
    	WdatePicker({onpicked:function(){$(this).change();},skin:'whyGreen',isShowClear:false});

    });   
    
    // 创建新行程checkbox
    $("#chkcreatetrip").bind("click", function() {
    	if($("#chkcreatetrip").attr("checked")==false){
    		
    		$("#newtripname").attr("disabled","disabled");
    		
    		$("#importtrip").removeAttr("disabled");
    		
    		$("#newtripnametr").css("display","none");
    		
    		$("#newtripname").attr("value","");
    		
    		$("#newtripnamesuccessdiv").css("display","none");  
    		
    	}else{
    		
    		$("#newtripname").removeAttr("disabled");
    		
    		$("#importtriptr").css("display","none");
    		
    		$("#importtripsuccessdiv").css("display","none");
    		
    		setSelected("importtrip","");
    		
    		$("#importtrip").attr("disabled","disabled");
    	}     	
    });     
    
    // 导入活动离开焦点事件
    
    $("#activestartcontent").bind("blur", function() {
    	if(!isImportCancelClick()){
    		chkactivestartcontent();   
    	}

    });       
    
    $("#activeendcontent").bind("blur", function() {
    	if(!isImportCancelClick()){
    		chkactiveendcontent();     
    	}

    });       
    
    $("#activestartaddr").bind("blur", function() {
    	if(!isImportCancelClick()){
    		chkactivestartaddr();      
    	}

    });    
    
    $("#activeendaddr").bind("blur", function() {
    	if(!isImportCancelClick()){
    		chkactiveendaddr();        
    	}

    });    
    
    $("#newtripname").bind("blur", function() {
    	if(!isImportCancelClick()){
    		chknewtripname();          
    	}

    });   
    
    $("#activestartcontent").bind("focus", function() {

		$("#activestartcontenttr").css("display","none");
		$("#activestartcontentsuccessdiv").css("display","none");           

    });       
    
    $("#activeendcontent").bind("focus", function() {

		$("#activeendcontenttr").css("display","none");
		$("#activeendcontentsuccessdiv").css("display","none");    		          

    });       
    
    $("#activestartaddr").bind("focus", function() {

		$("#activestartaddrtr").css("display","none");
		$("#activestartaddrsuccessdiv").css("display","none");           

    });    
    
    $("#activeendaddr").bind("focus", function() {

		$("#activeendaddrtr").css("display","none");
		$("#activeendaddrsuccessdiv").css("display","none");            

    });    
    
    $("#newtripname").bind("focus", function() {

		$("#newtripnametr").css("display","none");
		$("#newtripnamesuccessdiv").css("display","none");        

    });      
    
    // 时间select框改变值事件
    // 去掉，到达时间可能早于出发时间
    /*
    $("#activestartdate").bind("change", function() {
    	
    	chkactivtimevalidate();            

    });      
    
    $("#activestarthour").bind("change", function() {

    	chkactivtimevalidate();            

    });   
    
    $("#activestartmin").bind("change", function() {

    	chkactivtimevalidate();            

    });   
    
    $("#activeenddate").bind("change", function() {

    	chkactivtimevalidate();            

    });   
    
    $("#activeendhour").bind("change", function() {

    	chkactivtimevalidate();            

    });   
    
    $("#activeendmin").bind("change", function() {

    	chkactivtimevalidate();            

    });   
    */
    
    // 选择某个行程select改变值事件
    
    $("#importtrip").bind("change", function() {

    	chkvalidateimporttrip();            

    }); 
    
    $("#importtrip").bind("mousemove", function() {

    	if(document.all && window.external){
	        var tooltip = $("#ie6SelectTooltip");
	
	        if(-1 != this.selectedIndex){
	        
	            tooltip.html(this.options[this.selectedIndex].text);
	            
	            tooltip.css("display","block");            
	            
	        }    
    	}

    });   
    
    $("#importtrip").bind("mouseout", function() {

        var tooltip = $("#ie6SelectTooltip");
        
        tooltip.html("");
        
        tooltip.css("display","none");

    });     
    
    // 导入活动提交点击事件
    $("#importactivebutton").bind("click", function() {

    	// 所有验证通过
    	if(chkactivestartcontent()==0 
    			&& chkactivestartaddr()==0 
    			&& chkactiveendcontent()==0
    			&& chkactiveendaddr()==0
    			//&& chkactivtimevalidate()==0
    			&& chknewtripname()==0
    			&& chkvalidateimporttrip()==0){

    		// 用户选择行程（不是新建），验证该行程中是否有与之冲突的活动。
    		if($("#chkcreatetrip").attr("checked")==false){
    			
    			var retcode = checkImportActiveValidate();
    			
    			if(retcode == 0){
    				
    				importActiveAction();
    				
    			} else if(retcode == 1){
    				
    				$("#importtriptr").css("display","");
    				$("#importtripsuccessdiv").css("display","none");  
    				
    				$("#importtripinfodiv").css("display","");		
    				$("#importtripinfodiv").html("<img src=\""+$("#pro_path").val()+"\/image\/icon_error.gif"+"\" alt=\"验证错误\"  />&nbsp;&nbsp;<font color=\"red\">该行程创建的活动数已达最大数</font>");
    				
    				return;
    				
    			} else if(retcode == 2){

        			if(confirm("该时间已有活动安排，是否继续？")){
        				
        				importActiveAction();
        				
        			} else {
        				
        				return;
        				
        			}      				
    				
    			} 
    			
  			
    		} else {
    			
    			importActiveAction();
    			
    		}
    			    	
    	}else{
    		
    		return;
    		
    	}     

    });      
    
    function isImportCancelClick(){
    	
    	if(document.activeElement.id=="importactiveclosebutton" || 
    			document.activeElement.id=="importactivecancelbutton"){
    	
    		return true;
    		
    	} else {
    		
    		return false;
    		
    	}
    	
    }  

/**
 * 窗口最大化
 * @return
 */
function maxWindow(){

	if (document.all) {  
		
		window.moveTo(0,0);	
		
	    top.window.resizeTo(screen.availWidth,screen.availHeight);  

	}  
	// else if (document.layers||document.getElementById) {  

	//    if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){  

	//        top.window.outerHeight = screen.availHeight;  

	//        top.window.outerWidth = screen.availWidth;  

	//    }  
	// }  	
	
}
/**
 * 验证导入后动正确性
 * 
 * 	1、活动要加入的行程中是否存在时间冲突的活动
 * 	2、该行程是否已经达到最大值（50条活动）
 * 
 * @param tripid
 * @param times
 * @return 
 *  0 正常 1 存在时间冲突 2 已达最大值 3 存在时间冲突且已达最大值   
 * @throws Exception
 */
function checkImportActiveValidate(){
	
	var retcode = -1;
	
	dwr.engine.setAsync(false);
	
	var importtrip = $("#importtrip").val();
	
	var starttime = $("#activestartdate").val()+$("#activestarthour").val()+":"+$("#activestartmin").val();
	
	var endtime = $("#activeenddate").val()+$("#activeendhour").val()+":"+$("#activeendmin").val();
	
	var times = new Array(starttime,endtime);
	
	itripservice.checkImportActiveValidate(importtrip,"1",times,{
		
		  callback:function(data) { retcode = data;},
		  
		  errorHandler:function(message) {}
	
	});
	
	dwr.engine.setAsync(true);  	
	
	return retcode;
}

/**
 * 调用后台服务，导入后动
 * @return
 */
function importActiveAction(){
	// 起飞
	var impFirst = {
    	  activeDate:$("#activestartdate").val(),
    	  activeStartTime:$("#activestarthour").val()+":"+$("#activestartmin").val(),
    	  activeEndTime:"",
    	  activeType:$("#activestarttype").val(),
    	  activeContent:$("#activestartcontent").val(),
    	  activeAddr:$("#activestartaddr").val(),
    	  tripId:$("#importtrip").val(),
    	  tripName:$("#newtripname").val(),
    	  importType:"1",
    	  airLineTakeOff:$("#impAirLineTakeOff").val(),
    	  airLineArrive:$("#impAirLineArrive").val(),
    	  hotelCity:"",
    	  hotelName:""
    };
	
	// 抵达
    var impSecond = {	  
    	  activeDate:$("#activeenddate").val(),
    	  activeStartTime:$("#activeendhour").val()+":"+$("#activeendmin").val(),
    	  activeEndTime:"",
    	  activeType:$("#activeendtype").val(),
    	  activeContent:$("#activeendcontent").val(),
    	  activeAddr:$("#activeendaddr").val(),
    	  tripId:$("#importtrip").val(),
    	  tripName:$("#newtripname").val(),
    	  importType:"1",
    	  airLineTakeOff:$("#impAirLineTakeOff").val(),
    	  airLineArrive:$("#impAirLineArrive").val(),
    	  hotelCity:"",
    	  hotelName:"" 
	};
	
	itripservice.importActives(impFirst,impSecond,{
		  callback:function(data) {
			showimpactivesuccess();
		  },
		  errorHandler:function(message) {
			showimpactiveerror();    			  
		  }
	});
	
	loadimpactivebar();   	
}

/**
 * 处理验证Email结果
 * @return
 */
function chkEmail(){
	
	var result = validateemail($("#sendemailtxt").val());
	
	if(result == 0){
		$("#emailcheckinfotr").css("display","none");
		$("#emailchecksuccessdiv").css("display","none");
		//$("#emailchecksuccessdiv").html("<img src=\""+$("#pro_path").val()+"\/image\/onSuccess.gif"+"\" alt=\"验证正确\" />");
	}
	else if(result==-1){
		$("#emailcheckinfotr").css("display","");
		$("#emailchecksuccessdiv").css("display","none");    		
		$("#emailcheckinfodiv").html("<img src=\""+$("#pro_path").val()+"\/image\/icon_error.gif"+"\" alt=\"验证错误\"  />&nbsp;&nbsp;<font color=\"red\">请输入E-mail地址</font>");    		
	}
	else if(result<-1){
		$("#emailcheckinfotr").css("display","");
		$("#emailchecksuccessdiv").css("display","none");    		
		$("#emailcheckinfodiv").html("<img src=\""+$("#pro_path").val()+"\/image\/icon_error.gif"+"\" alt=\"验证错误\"  />&nbsp;&nbsp;<font color=\"red\">E-mail地址不合法，请重新输入</font>");        		
	}	
	return result;
}

/**
 * 验证邮箱
 * @return
 
function validateemail(email){
	var ret = -1000;
	if(email == ""){
		ret = -1;
	} else if(!/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(email)){
		ret = -2;
	} else {
		ret = 0;
	}
	return ret;
}*/

function validateemail(email){
	var ret = -1000;
	var splitString="";
	if(email == ""){
		ret = -1;
	} else if(!/^[a-zA-Z.0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(email)){
		ret = -2;
	}else if(email.length<5){
		ret = -2;
	}else{
		ret = 0;
	}
//slj
	if (email.substring(0,1) == '.' || email.substring(0,1) == '_' || email.substring(0,1) == '-')
	    ret = -2;
	    
	splitString = email.split("@");
	
	if (splitString[0].charAt(splitString[0].length - 1)  == '.' 
		|| splitString[0].charAt(splitString[0].length - 1)  == '_' 
		|| splitString[0].charAt(splitString[0].length - 1)  == '-')
	      ret = -2;	
	      
	return ret;
}

/**
 * 显示输入邮箱窗体
 * @return
 */
function showEmailForm(){
	
	if(isLogin()){
		$("#sendemailtxt").attr("value",$("#loginuseremail").val());	
	} else {
		$("#sendemailtxt").attr("value","");
	}
	
	$("#emailcheckinfotr").css("display","none");
	$("#emailchecksuccessdiv").css("display","none");
	
	$("#emaillightdiv").css("display","block");
	$("#sendemailcontentdiv").css("display","block");	

	$("#loadeamilbardiv").css("display","none");
	$("#sendemailerrordiv").css("display","none"); 
	$("#sendemailsuccessdiv").css("display","none");
	
	$("#emailfadediv").css("display","block");	
}

/**
 * 隐藏输入邮箱窗体
 * @return
 */
function hiddenEmailForm(){
	
	$("#emaillightdiv").css("display","none");
	$("#emailfadediv").css("display","none");	
}

/**
 * 显示邮件发送等待
 * @return
 */
function loadsendemailbar(){

	
	$("#sendemailcontentdiv").css("display","none");	

	$("#loadeamilbardiv").css("display","block");
	
	$("#sendemailerrordiv").css("display","none"); 
	
	$("#sendemailsuccessdiv").css("display","none");
		
}

/**
 * 显示邮件发送成功
 * @return
 */
function showsendemailsuccess(){
	
	$("#sendemailsuccessalertinfo").html("邮件已发送到 "+$("#sendemailtxt").val());
	
	$("#sendemailcontentdiv").css("display","none");	
	
	$("#loadeamilbardiv").css("display","none");
	
	$("#sendemailerrordiv").css("display","none"); 
	
	$("#sendemailsuccessdiv").css("display","block");	
	
	// $("#emailfadediv").css("display","none");
	
	// hidediv(document.getElementById("emaillightdiv"));
	
	setTimeout(hiddenEmailForm,1000);
	
}

/**
 * 显示邮件发送失败
 * @return
 */
function showsendemailerror(){
	
	$("#sendemailcontentdiv").css("display","none");	
	
	$("#loadeamilbardiv").css("display","none");
	
	$("#sendemailerrordiv").css("display","block"); 
	
	$("#sendemailsuccessdiv").css("display","none");
	
	// hidediv(document.getElementById("emaillightdiv"));
	
	setTimeout(hiddenEmailForm,3000);
}

/**
 * 处理验证手机号码结果
 * @return
 */
function chkMessage(){
	
	var result = validatemessage($("#sendmessagetxt").val());

	if(result == 0){
		$("#messagecheckinfotr").css("display","none");
		$("#messagechecksuccessdiv").css("display","none");
		//$("#messagechecksuccessdiv").html("<img src=\""+$("#pro_path").val()+"\/image\/onSuccess.gif"+"\" alt=\"验证正确\" />");
	}
	else if(result==-1){
		$("#messagecheckinfotr").css("display","");
		$("#messagechecksuccessdiv").css("display","none");    		
		$("#messagecheckinfodiv").html("<img src=\""+$("#pro_path").val()+"\/image\/icon_error.gif"+"\" alt=\"验证错误\"  />&nbsp;&nbsp;<font color=\"red\">手机号码不能为空</font>");    		
	}
	else if(result<-1){
		$("#messagecheckinfotr").css("display","");
		$("#messagechecksuccessdiv").css("display","none");    		
		$("#messagecheckinfodiv").html("<img src=\""+$("#pro_path").val()+"\/image\/icon_error.gif"+"\" alt=\"验证错误\"  />&nbsp;&nbsp;<font color=\"red\">手机号码不合法，请重新输入</font>");        		
	}	
	return result;
}

/**
 * 验证手机
 * @return
 */
function validatemessage(message){
	var ret = -1000;
	if(message == ""){
		ret = -1;
	} else if(!/^\d{11}$/.test(message)){
		ret = -2;
	} else {
		ret = 0;
	}
	return ret;
}

/**
 * 显示输入手机号码窗体
 * @return
 */
function showMessageForm(){
	
	if(isLogin()){
		$("#sendmessagetxt").attr("value",$("#loginusermobile").val());	
	} else {
		$("#sendmessagetxt").attr("value","");
	}
	
	$("#messagecheckinfotr").css("display","none");
	$("#messagechecksuccessdiv").css("display","none");
	
	$("#messagelightdiv").css("display","block");
	$("#sendmessagecontentdiv").css("display","block");	

	$("#loadmessagebardiv").css("display","none");
	$("#sendmessageerrordiv").css("display","none"); 
	$("#sendmessagesuccessdiv").css("display","none");
	
	$("#messagefadediv").css("display","block");	
}

/**
 * 隐藏输入手机号码窗体
 * @return
 */
function hiddenMessageForm(){
	
	$("#messagelightdiv").css("display","none");
	$("#messagefadediv").css("display","none");	
}

/**
 * 显示短信发送等待
 * @return
 */
function loadsendmessagebar(){

	
	$("#sendmessagecontentdiv").css("display","none");	

	$("#loadmessagebardiv").css("display","block");
	
	$("#sendmessageerrordiv").css("display","none"); 
	
	$("#sendmessagesuccessdiv").css("display","none");
		
}

/**
 * 显示短信发送成功
 * @return
 */
function showsendmessagesuccess(){
	
	$("#sendmessagecontentdiv").css("display","none");	
	
	$("#loadmessagebardiv").css("display","none");
	
	$("#sendmessageerrordiv").css("display","none"); 
	
	$("#sendmessagesuccessdiv").css("display","block");

	// $("#messagefadediv").css("display","none");	
	
	// hidediv(document.getElementById("messagelightdiv"));
	
	setTimeout(hiddenMessageForm,1000);
	
}

/**
 * 显示短信发送失败
 * @return
 */
function showsendmessageerror(){
	
	$("#sendmessagecontentdiv").css("display","none");	
	
	$("#loadmessagebardiv").css("display","none");
	
	$("#sendmessageerrordiv").css("display","block"); 
	
	$("#sendmessagesuccessdiv").css("display","none");	
	
	// hidediv(document.getElementById("messagelightdiv"));
	
	setTimeout(hiddenMessageForm,3000);
}


/**
 * 打开导入行程页面
 * @param obj 打开按钮对象
 * @param departTime 起飞时间
 * @param arrivalTime 到达时间
 * @param airline 航班
 * @param departAirport 起飞机场名称
 * @param arrivalAirport 到达机场名称
 * @param departCityCode 起飞机场所在城市三字码
 * @param arrivalCityCode 到达机场所在城市三字码
 * @return
 */
openImportActiveForm = function (obj,importformid){
	
	//if(actionCode!="RR"){
	//	if(!confirm("该航段还没有订妥，您确认把该航班加入行程安排吗？")){
	//		return;
	//	}
	//}
	
	var importActiveModel=new ModelDiv();
	
	initImportActiveForm(importformid);
	
    var top = document.documentElement.scrollTop;
    
    if(top > 150){
    	
    	top = top -150;
    }
    
	var left = document.body.clientWidth/2-200;

	importActiveModel.setOutDiv("importactivefadediv");

	importActiveModel.setInnerDiv("importactivelightdiv");

	importActiveModel.setHit(660);

	importActiveModel.setWid(470);

	importActiveModel.setTitle("导入活动");

	importActiveModel.setTop(top);

	importActiveModel.setLeft(left);

	importActiveModel.show();	
}

/**
 * 初始化导入活动窗口
 * @param departTime 起飞时间
 * @param arrivalTime 到达时间
 * @param airline 航班
 * @param departAirport 起飞机场名称
 * @param arrivalAirport 到达机场名称
 * @param departCityCode 起飞机场所在城市三字码
 * @param arrivalCityCode 到达机场所在城市三字码
 * @return
 */
function initImportActiveForm(importformid){
	
	var importFromObj = document.getElementById(importformid);
	
	var departTime = importFromObj.hidittravelDateForImport.value;
	var arrivalTime = importFromObj.hiditarrivalDateForImport.value;
	var airline = importFromObj.hiditairlineCode.value;
	var departAirport = importFromObj.hiditdepartAirportName.value;
	var arrivalAirport = importFromObj.hiditarrivalAirportName.value;
	var departCityCode = importFromObj.hiditdepartCityCode.value;
	var arrivalCityCode = importFromObj.hiditarrivalCityCode.value;		
	
	// 起飞时间
	var depart = departTime.split(" ");
	// 起飞日期
	var departDate = depart[0];
	// 起飞（小时）
	var departHour = depart[1];
	// 起飞（分）
	var departMinte = depart[2];
	
	// 到达时间
	var arrival = arrivalTime.split(" ");
	// 到达日期
	var arrivalDate = arrival[0];
	// 到达（小时）
	var arrivalHour = arrival[1];
	// 到达（分）
	var arrivalMinte = arrival[2];	
	
	// 传入的行程主键
	var tripid = $("#tripidforimport").val();
		
	$("#impAirLineTakeOff").attr("value",departCityCode);
	$("#impAirLineArrive").attr("value",arrivalCityCode);
	
	// 开始活动
	
	// 活动开始日期
	$("#activestartdate").attr("value",departDate);
	// 活动开始小时
	setSelected("activestarthour",departHour);
	// 活动开始分钟
	setSelected("activestartmin",departMinte);
	// 活动类型
	setSelected("activestarttype","0");
	// 活动内容
	$("#activestartcontent").attr("value",airline+" "+departAirport+"-"+arrivalAirport+" 航班起飞");
	// 活动地址
	$("#activestartaddr").attr("value",departAirport);
	
	// 结束活动
	
	// 活动日期
	$("#activeenddate").attr("value",arrivalDate);
	// 活动小时
	setSelected("activeendhour",arrivalHour);
	// 活动分钟
	setSelected("activeendmin",arrivalMinte);
	// 活动类型
	setSelected("activeendtype","0");
	// 活动内容
	$("#activeendcontent").attr("value",airline+" "+departAirport+"-"+arrivalAirport+" 航班抵达");
	// 活动地址
	$("#activeendaddr").attr("value",arrivalAirport);	
	
	// 行程信息
	
	// 选择是否新建行程
	$("#chkcreatetrip").attr("checked",false);
	
	// 加入到某个行程
	initTripSel(tripid);
	$("#importtrip").removeAttr("disabled");
	
	// 新行程名称
	$("#newtripname").attr("value","");
	$("#newtripname").attr("disabled","disabled");
	
	// 验证标签信息
	$("#activestartcontenttr").css("display","none");
	$("#activestartcontentsuccessdiv").css("display","none");
	$("#activestartcontentinfodiv").css("display","none");
	$("#activeendcontenttr").css("display","none");
	$("#activeendcontentsuccessdiv").css("display","none");
	$("#activeendcontentinfodiv").css("display","none");
	$("#activestartaddrtr").css("display","none");
	$("#activestartaddrsuccessdiv").css("display","none");
	$("#activestartaddrinfodiv").css("display","none");
	$("#activeendaddrtr").css("display","none");
	$("#activeendaddrsuccessdiv").css("display","none");
	$("#activeendaddrinfodiv").css("display","none");
	$("#newtripnametr").css("display","none");
	$("#importtriptr").css("display","none");
	$("#importtripsuccessdiv").css("display","none");
	$("#newtripnamesuccessdiv").css("display","none");
	$("#newtripnameinfodiv").css("display","none");
	$("#activeendtimetr").css("display","none");
	$("#activeendtimeinfodiv").css("display","none");	
	
	$("#importactivelightdiv").css("display","block");
	$("#importactivecontentdiv").css("display","block");	

	$("#loadimportactivebardiv").css("display","none");
	$("#sendimportactiveerrordiv").css("display","none"); 
	$("#sendimportactivesuccessdiv").css("display","none");
	
	$("#importactivefadediv").css("display","block");	

	// 提交请求后显示的div
	
	$("#loadimportactivebardiv").css("display","none");
	
	$("#importactiveerrordiv").css("display","none"); 
	
	$("#importactivesuccessdiv").css("display","none");	

}

/**
 * 初始化我的行程列表
 * @param tripid
 * @return
 */
function initTripSel(tripid){

	$("#importtrip").empty();
	
	//$("<option value=''></option>").appendTo("#importtrip");
	
	var sels;
	
	dwr.engine.setAsync(false);
		
	itripservice.queryMyTrips({
		  callback:function(data) {
			sels = data;
		  },
		  errorHandler:function(message) {
			   			  
		  }
	});	
	
	dwr.engine.setAsync(true); 
	
	for(var n in sels){
		
	   $("<option value='"+sels[n][0]+"' title='"+sels[n][1]+"'>"+sels[n][1]+"</option>").appendTo("#importtrip");
	   
	}	
	
	setSelected("importtrip",tripid);
}

/**
 * 设置选择框被选中
 * @param selName
 * @param text
 * @return
 */
function setSelected(selName,text){
	
	var slt=document.getElementById(selName);

	if(text == ""){
		slt.selectedIndex = -1;
	} else {
		for(var i=0;i<slt.options.length;i++){
			if(slt.options[i].value==text){
				slt.options[i].selected=true;
				break;
			}
		}
	}
}

/**
 * 隐藏导入活动窗体
 * @return
 */
function hiddenImportActiveForm(){
	
	$("#importactivelightdiv").css("display","none");
	$("#importactivefadediv").css("display","none");	
}

// 导入活动验证

/**
 * 处理验证航班起飞活动内容
 */
function chkactivestartcontent(){
	
	var result = validateactivestartcontent($("#activestartcontent").val());
	
	if(result == 0){
		$("#activestartcontenttr").css("display","none");
		$("#activestartcontentsuccessdiv").css("display","none");    		
		//$("#activestartcontentsuccessdiv").html("<img src=\""+$("#pro_path").val()+"\/image\/onSuccess.gif"+"\" alt=\"验证正确\" />");
	}
	else if(result==-1){
		$("#activestartcontenttr").css("display","");
		$("#activestartcontentsuccessdiv").css("display","none");  
		
		$("#activestartcontentinfodiv").css("display","");		
		$("#activestartcontentinfodiv").html("<img src=\""+$("#pro_path").val()+"\/image\/icon_error.gif"+"\" alt=\"验证错误\"  />&nbsp;&nbsp;<font color=\"red\">请输入活动内容</font>");    		
	}	
	else if(result==-2){
		$("#activestartcontenttr").css("display","");
		$("#activestartcontentsuccessdiv").css("display","none");  
			
		$("#activestartcontentinfodiv").css("display","");
		$("#activestartcontentinfodiv").html("<img src=\""+$("#pro_path").val()+"\/image\/icon_error.gif"+"\" alt=\"验证错误\"  />&nbsp;&nbsp;<font color=\"red\">活动内容长度过长</font>");    		
	} 	
	return result;	
}

		String.prototype.trim = function(){
		  //用正则表达式将前后空格用空字符串替代。      
		    var value = this.replace(/(^\s*)|(\s*$)/g, "");    
		    return value.replace(/(^　*)|(　*$)/g, "");    
		}

/**
 * 验证航班起飞活动内容
 * @return
 */
function validateactivestartcontent(activestartcontent){
	
	var ret = -1000;
	
	var activestartcontentLen = activestartcontent.length;
	
//	if($.trim(activestartcontent) ==""){
// slj
	if(activestartcontent.trim() == ""){
		ret = -1;
	} else if(activestartcontentLen>150){
		ret = -2;
	} else {
		ret = 0;
	}
	
	return ret;
}

/**
 * 处理验证航班抵达活动内容
 */
function chkactiveendcontent(){
	
	var result = validateactiveendcontent($("#activeendcontent").val());
	
	if(result == 0){
		$("#activeendcontenttr").css("display","none");
		$("#activeendcontentsuccessdiv").css("display","none");    		
		//$("#activeendcontentsuccessdiv").html("<img src=\""+$("#pro_path").val()+"\/image\/onSuccess.gif"+"\" alt=\"验证正确\" />");
	}
	else if(result==-1){
		$("#activeendcontenttr").css("display","");
		$("#activeendcontentsuccessdiv").css("display","none");  
		
		$("#activeendcontentinfodiv").css("display","");		
		$("#activeendcontentinfodiv").html("<img src=\""+$("#pro_path").val()+"\/image\/icon_error.gif"+"\" alt=\"验证错误\"  />&nbsp;&nbsp;<font color=\"red\">请输入活动内容</font>");    		
	}	
	else if(result==-2){
		$("#activeendcontenttr").css("display","");
		$("#activeendcontentsuccessdiv").css("display","none");  
					
		$("#activeendcontentinfodiv").css("display","");
		$("#activeendcontentinfodiv").html("<img src=\""+$("#pro_path").val()+"\/image\/icon_error.gif"+"\" alt=\"验证错误\"  />&nbsp;&nbsp;<font color=\"red\">活动内容长度过长</font>");    		
	} 	
	return result;	
}


/**
 * 验证航班起抵达动内容
 * @return
 */
function validateactiveendcontent(activeendcontent){
	
	var ret = -1000;
	
	var activeendcontentLen = activeendcontent.length;
	
//	if($.trim(activeendcontent) ==""){
//slj
	if(activeendcontent.trim() == ""){
		ret = -1;
	} else if(activeendcontentLen>150){
		ret = -2;
	} else {
		ret = 0;
	}
	
	return ret;
}


/**
 * 处理验证航班起飞活动地点
 */
function chkactivestartaddr(){
	
	var result = validateactivestartaddr($("#activestartaddr").val());
	
	if(result == 0){
		$("#activestartaddrtr").css("display","none");
		$("#activestartaddrsuccessdiv").css("display","none");    		
		//$("#activestartaddrsuccessdiv").html("<img src=\""+$("#pro_path").val()+"\/image\/onSuccess.gif"+"\" alt=\"验证正确\" />");
	}
	else if(result==-1){
		$("#activestartaddrtr").css("display","");
		$("#activestartaddrsuccessdiv").css("display","none");  
		
		$("#activestartaddrinfodiv").css("display","");		
		$("#activestartaddrinfodiv").html("<img src=\""+$("#pro_path").val()+"\/image\/icon_error.gif"+"\" alt=\"验证错误\"  />&nbsp;&nbsp;<font color=\"red\">请输入活动地点</font>");    		
	}	
	else if(result==-2){
		$("#activestartaddrtr").css("display","");
		$("#activestartaddrsuccessdiv").css("display","none");  
			
		$("#activestartaddrinfodiv").css("display","");
		$("#activestartaddrinfodiv").html("<img src=\""+$("#pro_path").val()+"\/image\/icon_error.gif"+"\" alt=\"验证错误\"  />&nbsp;&nbsp;<font color=\"red\">活动地点长度过长</font>");    		
	} 	
	return result;	
}


/**
 * 验证航班起飞活动地点
 * @return
 */
function validateactivestartaddr(activestartaddr){
	
	var ret = -1000;
	
	var activestartaddrLen = activestartaddr.length;
	
//	if($.trim(activestartaddr) ==""){
//slj
	if(activestartaddr.trim() == ""){
		ret = -1;
	} else if(activestartaddrLen>150){
		ret = -2;
	} else {
		ret = 0;
	}
	
	return ret;
}

/**
 * 处理验证航班抵达活动地点
 */
function chkactiveendaddr(){
	
	var result = validateactiveendaddr($("#activeendaddr").val());
	
	if(result == 0){
		$("#activeendaddrtr").css("display","none");
		$("#activeendaddrsuccessdiv").css("display","none");    		
		//$("#activeendaddrsuccessdiv").html("<img src=\""+$("#pro_path").val()+"\/image\/onSuccess.gif"+"\" alt=\"验证正确\" />");
	}
	else if(result==-1){
		$("#activeendaddrtr").css("display","");
		$("#activeendaddrsuccessdiv").css("display","none");  
		
		$("#activeendaddrinfodiv").css("display","");		
		$("#activeendaddrinfodiv").html("<img src=\""+$("#pro_path").val()+"\/image\/icon_error.gif"+"\" alt=\"验证错误\"  />&nbsp;&nbsp;<font color=\"red\">请输入活动地点</font>");    		
	}	
	else if(result==-2){
		$("#activeendaddrtr").css("display","");
		$("#activeendaddrsuccessdiv").css("display","none");  
					
		$("#activeendaddrinfodiv").css("display","");
		$("#activeendaddrinfodiv").html("<img src=\""+$("#pro_path").val()+"\/image\/icon_error.gif"+"\" alt=\"验证错误\"  />&nbsp;&nbsp;<font color=\"red\">活动地点长度过长</font>");    		
	} 	
	return result;	
}


/**
 * 验证航班起抵达活动地点
 * @return
 */
function validateactiveendaddr(activeendaddr){
	
	var ret = -1000;
	
	var activeendaddrLen = activeendaddr.length;
	
//	if($.trim(activeendaddr) ==""){
//slj
	if(activeendaddr.trim() == ""){
		ret = -1;
	} else if(activeendaddrLen>150){
		ret = -2;
	} else {
		ret = 0;
	}
	
	return ret;
}

/**
 * 处理验证行程名称
 */
function chknewtripname(){
	
	var result = validatenewtripname($("#newtripname").val());
	
	if(result == 0){
		$("#newtripnametr").css("display","none");
		$("#newtripnamesuccessdiv").css("display","none");    		
		//$("#newtripnamesuccessdiv").html("<img src=\""+$("#pro_path").val()+"\/image\/onSuccess.gif"+"\" alt=\"验证正确\" />");
	}
	else if(result==-1){
		$("#newtripnametr").css("display","");
		$("#newtripnamesuccessdiv").css("display","none");  
		
		$("#newtripnameinfodiv").css("display","");		
		$("#newtripnameinfodiv").html("<img src=\""+$("#pro_path").val()+"\/image\/icon_error.gif"+"\" alt=\"验证错误\"  />&nbsp;&nbsp;<font color=\"red\">请输入行程名称</font>");    		
	}	
	else if(result==-2){
		$("#newtripnametr").css("display","");
		$("#newtripnamesuccessdiv").css("display","none");  
					
		$("#newtripnameinfodiv").css("display","");
		$("#newtripnameinfodiv").html("<img src=\""+$("#pro_path").val()+"\/image\/icon_error.gif"+"\" alt=\"验证错误\"  />&nbsp;&nbsp;<font color=\"red\">行程名称长度过长</font>");    		
	} 
	else if(result==-3){
		
		$("#newtripnametr").css("display","");
		$("#newtripnamesuccessdiv").css("display","none");  
					
		$("#newtripnameinfodiv").css("display","");
		$("#newtripnameinfodiv").html("<img src=\""+$("#pro_path").val()+"\/image\/icon_error.gif"+"\" alt=\"验证错误\"  />&nbsp;&nbsp;<font color=\"red\">行程名称中含有非法字符</font>");		
		
	}
	
	return result;	
}


/**
 * 验证行程名称
 * @return
 */
function validatenewtripname(newtripname){
	
	var ret = -1000;
	
	var newtripnameLen = newtripname.length;
	
	if($("#newtripname").attr("disabled")==true){
		ret = 0;
	} else if($.trim(newtripname) ==""){
		ret = -1;
	} else if(newtripnameLen>30){
		ret = -2;
	} else if(!/^[\dA-Za-z\u4E00-\u9FA5\uF900-\uFA2D]+$/.test(newtripname)){
		ret = -3;
	} else {
		ret = 0;
	}
	
	return ret;
}

/**
 * 处理结束时间是否早于开始时间
 */
function chkactivtimevalidate(){
	
	var result = activtimevalidate();
	
	if(result == 0){
		$("#activeendtimetr").css("display","none");
	}	
	else if(result==-1){
		$("#activeendtimetr").css("display","");
		$("#activeendtimeinfodiv").css("display","");
		$("#activeendtimeinfodiv").html("<img src=\""+$("#pro_path").val()+"\/image\/icon_error.gif"+"\" alt=\"验证错误\"  />&nbsp;&nbsp;<font color=\"red\">航班抵达日期早于起飞日期，请重新选择</font>");    		
	} 
	
	return result;	
}

/**
 * 处理验证加入某个行程为空且没有选择创建行程结果
 */
function chkvalidateimporttrip(){
	
	var result = validateimporttrip();
	
	if(result == 0){
		$("#importtriptr").css("display","none");
		$("#importtripsuccessdiv").css("display","none");    		
		//$("#importtripsuccessdiv").html("<img src=\""+$("#pro_path").val()+"\/image\/onSuccess.gif"+"\" alt=\"验证正确\" />");
	}
	else if(result==-1){
		$("#importtriptr").css("display","");
		$("#importtripsuccessdiv").css("display","none");  
		
		$("#importtripinfodiv").css("display","");		
		$("#importtripinfodiv").html("<img src=\""+$("#pro_path").val()+"\/image\/icon_error.gif"+"\" alt=\"验证错误\"  />&nbsp;&nbsp;<font color=\"red\">请选择行程或创建新行程</font>");    		
	}
	
	return result;	
}

/**
 * 验证加入某个行程为空且没有选择创建行程
 * @return
 */
function validateimporttrip(){
	
	var ret = 0;
	
	var start = $("#importtrip").val();
//	alert(start);
	
	if(start==null && $("#chkcreatetrip").attr("checked")==false){
		ret = -1;
	}
	
	return ret;
}

/**
 * 验证结束时间是否早于开始时间
 * @return
 */
function activtimevalidate(){
	
	var ret = 0;
	
	var start = $("#activestartdate").val()+
				$("#activestarthour").val()+
				$("#activestartmin").val();
	
	var end = $("#activeenddate").val()+
			  $("#activeendhour").val()+
			  $("#activeendmin").val();
	
	if(end < start ){
		ret = -1;
	} else {
		ret = 0;
	}
	return ret;
}

/**
 * 显示导入活动成功
 * @return
 */
function showimpactivesuccess(){
	
	$("#importactivecontentdiv").css("display","none");	
	
	$("#loadimportactivebardiv").css("display","none");
	
	$("#importactiveerrordiv").css("display","none"); 
	
	$("#importactivesuccessdiv").css("display","block");	
	
	// $("#importactivefadediv").css("display","none");
	
	// hidediv(document.getElementById("importactivelightdiv"));
	
	setTimeout(hiddenImportActiveForm,1000);
	
	// 刷新父页面
	if($("#tripidforimport").val()!=""){
		window.opener.location=$("#pro_path").val()+"/queryactive.htm?tripid="+$("#tripidforimport").val();
	}
		
}

/**
 * 显示导入活动失败
 * @return
 */
function showimpactiveerror(){
	
	$("#importactivecontentdiv").css("display","none");	
	
	$("#loadimportactivebardiv").css("display","none");
	
	$("#importactiveerrordiv").css("display","block"); 
	
	$("#importactivesuccessdiv").css("display","none");	
	
	// hidediv(document.getElementById("importactivelightdiv"));
	
	setTimeout(hiddenImportActiveForm,3000);
}

/**
 * 显示导入活动等待
 * @return
 */
function loadimpactivebar(){

	
	$("#importactivecontentdiv").css("display","none");	

	$("#loadimportactivebardiv").css("display","block");
	
	$("#importactiveerrordiv").css("display","none"); 
	
	$("#importactivesuccessdiv").css("display","none");
		
}

/**
 * 未登录确认窗体函数
 */
nologonConfirmFrom = function(obj){

	var preloginmodel=new ModelDiv();
	
	$("#preloginfadediv").css("display","block");
	
	$("#preloginlightdiv").css("display","block");	

	var top = $(obj).offset().top;
	
    var scrollTop = document.documentElement.scrollTop;
    
    if (top - scrollTop > 350) {
    	
    	window.scrollTo(0, scrollTop + 336);
    	
    } 	
	
	var left = document.body.clientWidth/2-200;

	preloginmodel.setOutDiv("preloginfadediv");

	preloginmodel.setInnerDiv("preloginlightdiv");

	preloginmodel.setHit(100);

	preloginmodel.setWid(260);

	preloginmodel.setTitle("未登录确认");

	preloginmodel.setTop(top);

	preloginmodel.setLeft(left);

	preloginmodel.show();	
	
}

/**
 * 隐藏未登录确认窗体
 */
function hiddenNologonConfirmFrom(){
	
	$("#preloginfadediv").css("display","none");
	
	$("#preloginlightdiv").css("display","none");		
	
}

// 隐藏未登录确认窗体窗口
$("#preloginclosebutton").click(function(){
	hiddenNologonConfirmFrom();  	
});	 

//隐藏未登录确认窗体窗口
$("#preloginhidformclosebutton").click(function(){
	hiddenNologonConfirmFrom();  	
});	

// 确认登录
$("#preloginbutton").click(function(){
	
	hiddenNologonConfirmFrom();
	
	window.location = $("#pro_path").val() + "/viewLogin.htm";
	
});	 

});

/**
 * IE 中图片不存在的处理办法
 * @param obj
 * @return
 */
function imgErr(obj){
    obj.parentNode.innerHTML="";
}
